﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

using System.Data;

public partial class product_saving_admin_deposits : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
      

    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {

        decimal amount = decimal.Parse(tbAmount.Text);
        string strType = "DEPOSIT";
        string strTo = tbTo.Text;
        string strStatus = "SUCCESS";



        string strConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        SqlConnection myConnection = new SqlConnection(strConnectionString);

        try
        {
            myConnection = DBManager.getSqlConnection();
            SqlCommand myCommandd = new SqlCommand("INSERT INTO SUMMARY(transactionDate, transactionType, transactionStatus, accountNo, transactionAmount)" + "VALUES(@date, @type, @status, @accNo, @transactionAmount)", myConnection);
            myConnection.Open();
            myCommandd.Parameters.AddWithValue("@date", DateTime.Now);
            myCommandd.Parameters.AddWithValue("@type", strType);
            myCommandd.Parameters.AddWithValue("@status", strStatus);
            myCommandd.Parameters.AddWithValue("@accNo", tbTo.Text);
            myCommandd.Parameters.AddWithValue("@transactionAmount", amount);
            myCommandd.ExecuteNonQuery();

            myConnection = DBManager.getSqlConnection();
            SqlCommand myCommandp = new SqlCommand("update [SAVING_ACCOUNT] SET [balance] = balance+" + amount + " WHERE [accountNo] = " + tbTo.Text, myConnection);
            myConnection.Open();
            myCommandp.Parameters.AddWithValue("@balance", amount);
            myCommandp.Parameters.AddWithValue("@account", tbTo.Text);
            myCommandp.ExecuteNonQuery();


            Label1.Text = "Deposit Success, please log in to check for the updated balance. Thank you.";

            myConnection.Close();
        }
        catch (System.Data.SqlClient.SqlException ex)
        {
            Response.Write(ex);
        }
        finally
        {
            myConnection.Close();
        }
    }

}
